<template>
  <div class="login-container">
    <div class="nav">
      <div class="navLeft">
        <img src="../../assets/images/tab_index_selected@3x.png" />
        <span class="fg">|</span>
        <span>天渡运营管理后台</span>
      </div>
      <div class="navRight">您好，欢迎使用天渡运营管理后台，请登录！</div>
    </div>
    <el-form ref="loginForm" :model="loginForm" class="login-form" label-position="left">
      <div class="title-container">
        <h3 class="title">登录天渡</h3>
      </div>
      <el-form-item>
        <div class="tag">账号</div>
        <el-input v-model="loginForm.username" placeholder="请输入用户名" type="text" />
      </el-form-item>

      <el-form-item>
        <div class="tag">密码</div>
        <el-input
          v-model="loginForm.password"
          placeholder="请输入密码"
          type="password"
          @keyup.enter.native="handleLogin"
        ></el-input>
      </el-form-item>

      <el-form-item class="checkbox">
        <el-checkbox v-model="loginForm.remember" @change="rememberChange">记住密码</el-checkbox>
      </el-form-item>

      <el-button
        class="loginButton"
        :loading="loading"
        type="primary"
        style="width:250px"
        @click.native.prevent="handleLogin"
      >登录</el-button>

      <!-- <div class="tips">
        <span style="margin-right:20px;">username: admin</span>
        <span>password: any</span>
      </div>-->
    </el-form>
  </div>
</template>

<script>
import { validUsername } from "@/utils/validate";

export default {
  name: "Login",
  created() {
    // if (localStorage.getItem("remember") == "true") {
    //   this.loginForm.remember = true;
    //   this.getCache();
    // }
  },
  data() {
    return {
      loginForm: {
        username: "zyj",
        password: "123456",
        remember: false,
      },
      loading: false,
      passwordType: "password",
      redirect: undefined,
      pwdVisible: false,
    };
  },
  watch: {
    $route: {
      handler: function (route) {
        this.redirect = route.query && route.query.redirect;
      },
      immediate: true,
    },
  },
  methods: {
    rememberChange(e) {
      console.log(e);
    },
    handleLogin() {
      let self = this;
      this.loading = true;
      this.$store
        .dispatch("user/login", this.loginForm)
        .then(() => {
          this.$router.push({ path: "/" });
          this.loading = false;
        })
        .catch(() => {
          this.loading = false;
        });
    },
  },
};
</script>

<style lang="scss">
/* 修复input 背景不协调 和光标变色 */
/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */

$bg: #283443;
$light_gray: #c19d6b;
$cursor: #c19d6b;

@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  .login-container .el-input input {
    color: $cursor;
  }
}

.navLeft {
  display: flex;
  align-items: center;
  font-size: 18px;
  font-weight: 600;
  img {
    width: 47px;
    margin-top: -8px;
  }

  .fg {
    font-weight: 200;
    margin: 0 22px;
    color: #d8d8d8;
  }
}

.loginButton {
  background: #c19d6b;
  border-color: #c19d6b;
  color: #ffffff;
  font-weight: bold;
  width: 250px;
  margin-top: 16px;
  height: 48px;
  font-size: 16px;
  &:hover {
    opacity: 0.6;
    background: #c19d6b;
    border-color: #c19d6b;
  }
  &:focus {
    opacity: 0.6;
    background: #c19d6b;
    border-color: #c19d6b;
  }
}

.tag {
  color: #999999;
  font-size: 14px;
  line-height: 14px;
}

/* reset element-ui css */
.login-container {
  .el-input {
    display: inline-block;
    height: 47px;
    line-height: 47px;
    width: 100%;

    input {
      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 0;
      color: #222222;
      height: 40px;
      caret-color: #c19d6b;
      border-bottom: 1px solid #999999;

      &:-webkit-autofill {
        box-shadow: 0 0 0px 1000px #fff inset !important;
        -webkit-text-fill-color: #222222 !important;
      }
      &:focus {
        transition: width 0.6s;
        border-bottom: 2px solid #c19d6b;
      }
    }
  }

  .el-form-item {
    width: 250px;
  }
}

.checkbox {
  margin-bottom: 0;
  // 未选中样式
  .el-checkbox .el-checkbox__inner {
    color: #999999;
    border-radius: 0;
    border-color: #999999;
  }
  .el-checkbox__input.is-checked + .el-checkbox__label {
    color: #c19d6b;
  }
  .el-checkbox__input.is-checked .el-checkbox__inner {
    background-color: #c19d6b;
    border-color: #c19d6b;
  }
}
</style>

<style lang="scss" scoped>
$bg: #2d3a4b;
// $dark_gray: #889aa4;
$light_gray: #eee;

.nav {
  height: 68px;
  background: #fff;
  font-size: 14px;
  color: #666666;
  justify-content: space-between;
  display: flex;
  align-items: center;
  padding: 0 50px;
}

.login-container {
  min-height: 100%;
  width: 100%;
  background: #c19d6b;
  overflow: hidden;

  .login-form {
    position: relative;
    width: 420px;
    max-width: 100%;
    padding: 40px 85px;
    margin: 0 auto;
    margin-top: 140px;
    overflow: hidden;
    background: #fff;
    border-radius: 4px;
    box-shadow: 0 12px 4px 0 rgba(49, 45, 40, 0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;

    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }

  .svg-container {
    padding: 6px 5px 6px 15px;
    // color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }

  .title-container {
    position: relative;

    .title {
      font-size: 18px;
      color: #000000;
      margin: 0px auto 40px auto;
      text-align: center;
    }
  }

  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    // color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }
}
</style>
